/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jollylengkono.skripsi.Departments.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jollylengkono.skripsi.Departments.form.DepartmentsUpdateForm;
import jollylengkono.skripsi.dao.DepartmentsDao;
import jollylengkono.skripsi.dao.MembersDao;
import jollylengkono.skripsi.model.Departments;
import jollylengkono.skripsi.model.Members;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author hp02
 */
public class DepartmentsUpdate extends Action {
    private String FORWARD;
    private int STATE;

    public DepartmentsUpdate() {
    }
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        DepartmentsUpdateForm deptForm = (DepartmentsUpdateForm) form;
        Departments department = new Departments();
        department.setDepartmentChief((Members) new MembersDao().read(deptForm.getDepartmentChief()));
        department.setDepartmentName(deptForm.getDepartmentName());
        department.setId(deptForm.getId());
        this.STATE = new DepartmentsDao().update(department);
        if (this.STATE==1) {
            this.FORWARD="success";
        } else {
            this.FORWARD="fail";
        }
        return mapping.findForward(FORWARD);
    }
}
